//
//  KQMessageQuestionContentCell.swift
//  KangYunYouJia
//
//  Created by zhouxiang on 2020/12/17.
//  Copyright © 2020 zhoux@zzkqdc.com. All rights reserved.
//

import UIKit

class KQMessageQuestionContentCell: UITableViewCell {
    
    @IBOutlet weak var titleLabel: UILabel!
    
    /// 打电话的按钮
    @IBOutlet weak var callButton: UIButton!
    
    @IBOutlet weak var rightForTitleLabel: NSLayoutConstraint!
    
    // MARK: - life cycle
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    // MARK: - public methods
    /// 设置数据
    public func setData(model: KQMessageQuestionContent?) {
        self.titleLabel.text = model?.question
        let type = model?.questionMsgType?.code ?? ""
        if type == "1" {
            // 打电话
            self.callButton.isHidden = false
            self.callButton.setImage(UIImage(named: "kq_chat_phone.png"), for: .normal)
            self.rightForTitleLabel.constant = 34
        } else if type == "2" {
            // 跳转链接
            self.callButton.isHidden = false
            self.callButton.setImage(UIImage(named: "kq_chat_url.png"), for: .normal)
            self.rightForTitleLabel.constant = 34
        } else {
            // 问答
            self.callButton.isHidden = true
            self.rightForTitleLabel.constant = 10
        }
        self.layoutIfNeeded()
    }
    
    /// 获取高度
    public class func getCellHeight(model: KQMessageQuestionContent?) -> CGFloat {
        let type = model?.questionMsgType?.code ?? ""
        var width: CGFloat = 0
        if type == "1" {
            // 打电话
            width = 206.0
        } else if type == "2" {
            // 跳转链接
            width = 206.0
        } else {
            // 问答
            width = 230.0
        }
        let height = KQChatUtils.shared().sizeThatFits(CGSize(width: width, height: CGFloat.greatestFiniteMagnitude), font: UIFont(name: KQCHAT_FONT_NAME, size: 14)!, text: model?.question ?? "").height
        return max(40.0, height + 19.0)
    }
    
}
